package acm.广度优先搜索;

import org.junit.Test;

import java.math.BigInteger;
import java.util.*;

public class D {

    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n;
        while ((n=sc.nextInt())!=0){
            System.out.println(bfs(n));
//            System.out.println(bfs2(n));
        }
    }
    /**
     * 宽度优先遍历
     */
    public static String bfs(int n){
        BigInteger bigN=new BigInteger(""+n);
        BigInteger zero=new BigInteger("0");
        Queue<String> queue=new LinkedList<String>();
        queue.add("1");
        while (!queue.isEmpty()){
            String str = queue.poll();
            BigInteger curr=new BigInteger(str);
            if (curr.mod(bigN).equals(zero)){
                return str;
            }
            if (str.length()>=100){
                continue;
            }
            queue.add(str+"0");
            queue.add(str+"1");
        }
        return null;
    }

    @Test
    public void test(){
        bigN=new BigInteger("6");
        chars[0]='1';
        int count = dfs(1);
        System.out.println(new String(chars,0,count));
    }
    static char[] chars=new char[100];
    static BigInteger bigN;
    static BigInteger zero=new BigInteger("0");
    public static int dfs(int index){
        if (index>=100){
            return -1;
        }
        BigInteger res = new BigInteger(new String(chars, 0, index));
        if (res.mod(bigN).equals(zero)){
            return index;
        }
        chars[index]='0';
        int dfs1 = dfs(index + 1);
        if (dfs1!=-1){
            return dfs1;
        }
        chars[index]='1';
        int dfs = dfs(index + 1);
        return dfs;
    }
}
